package operatebag;

import operatebag.bag.*;
import people.Student;
import mysqloperate.*;
import people.User;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class changstudent extends JFrame {

    JButton change;
    JButton cancal;
    JLabel id;
    JTextField idtxt;
    JFrame jf;


    public changstudent(){
        setTitle("修改学生");
        setDefaultCloseOperation(DISPOSE_ON_CLOSE);
        setLayout(new FlowLayout());
        setBounds(500,200,400,400);
        setResizable(false);
        setVisible(true);
        jf=this;

        id=new JLabel("请输入要修改的学生学号");
        idtxt=new JTextField(15);
        Box b=Box.createVerticalBox();
        Box b1=Box.createHorizontalBox();
        b1.add(id);
        b1.add(idtxt);

        Box b2=Box.createHorizontalBox();
        change=new JButton("确定");
        cancal=new JButton("取消");
        b2.add(change);
        b2.add(cancal);

        b.add(b1);
        b.add(Box.createVerticalStrut(25));
        b.add(b2);
        add(b);
        change.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                String id=idtxt.getText();
                Object ob[][];
                try {
                    ob = searchstu.search();
                } catch (Exception ex) {
                    throw new RuntimeException(ex);
                }
                try {
                    if(searchstu.youwuid(id,ob)==true){
                        /*Student student=new Student();
                        for(int i=0;i<ob.length;i++){
                            if(id.equals(ob[i][0])){
                                Object stu[]=ob[i];
                                student.setStudentid(stu[0].toString());
                                student.setName(stu[1].toString());
                                student.setSEX(Integer.parseInt(stu[2].toString()));
                                student.setBirth(stu[3].toString());
                                student.setMath(Integer.parseInt(stu[4].toString()));
                                student.setJava(Integer.parseInt(stu[5].toString()));
                                student.setPe(Integer.parseInt(stu[6].toString()));
                                break;
                            }
                        }*/
                        new showstudent();
                        new changitem(id);
                    }else {
                        JOptionPane.showMessageDialog(jf, "没有此学生","",JOptionPane.INFORMATION_MESSAGE);
                    }

                } catch (Exception ex) {
                    throw new RuntimeException(ex);
                }
            }
        });
        cancal.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                jf.dispose();
            }
        });

    }


}
